﻿using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class libraryScene : MonoBehaviour
{
    public Material[] m_material = new Material[6];
    int PhotoID = 0;
    // Use this for initialization
    void Start()
    {
        try
        {
            this.GetComponent<Renderer>().material = m_material[0];
            //PhotoElements(PhotoID);
        }
        catch { }
    }

    // Update is called once per frame
    void Update()
    {

    }

    public void PhotoChangeAdd()
    {
        try
        {
            //点击按钮更换下一张图片
            this.GetComponent<Renderer>().material = m_material[++PhotoID];
            //PhotoElements(PhotoID);
        }
        catch
        {
            PhotoID = m_material.Length;
        }

    }

    public void PhotoChangeMinus()
    {
        try
        {
            //点击按钮更换前一张图片
            this.GetComponent<Renderer>().material = m_material[--PhotoID];
            //PhotoElements(PhotoID);
        }
        catch
        {
            PhotoID = 0;
        }
    }

    public void PhotoReset()
    {
        //点击按钮恢复第一张图片
        PhotoID = 0;
        this.GetComponent<Renderer>().material = m_material[0];
    }

    public void VRmode()
    {
        Cardboard.SDK.VRModeEnabled = !Cardboard.SDK.VRModeEnabled;
    }

    public void Quit()
    {
        SceneManager.LoadScene("mapScene");
    }

    //各种各样的图片事件
    public void PhotoElements(int photoID)
    {
        //根据图片的序号选择相对应的图片事件
        int selection = 0;
        switch (photoID)
        {
            case 0: case 1: selection = 1; break;
            case 3: break;
            default: selection = 0; break;
        }
        GameObject goButton = GameObject.Find("PhotoAdd");//增加的按钮
        GameObject backButton = GameObject.Find("PhotoMinus");//减少的按钮
        Vector3 positionGo = new Vector3(); Vector3 positionBack = new Vector3();
        Vector3 rotationGo = new Vector3(); Vector3 rotationBack = new Vector3();

        positionGo = new Vector3(100, 500, -50);
        rotationGo = new Vector3(0, 0, 0);
        goButton.GetComponent<RectTransform>().localPosition = positionGo;
        goButton.GetComponent<RectTransform>().eulerAngles = rotationGo;
        positionBack = new Vector3(100, 500, -50);
        rotationBack = new Vector3(0, 0, 0);
        backButton.GetComponent<RectTransform>().localPosition = positionBack;
        backButton.GetComponent<RectTransform>().eulerAngles = rotationBack;

        //图片事件开始
        if (selection == 1)//如果是第一种事件
        {
            //前进按钮的位置和旋转
            positionGo = new Vector3(100, 500, -50);
            rotationGo = new Vector3(0, 0, 0);
            goButton.GetComponent<RectTransform>().localPosition = positionGo;
            goButton.GetComponent<RectTransform>().eulerAngles = rotationGo;
            //后退按钮的位置和旋转
            positionBack = new Vector3(50, 500, -50);
            rotationBack = new Vector3(0, 0, 0);
            backButton.GetComponent<RectTransform>().localPosition = positionBack;
            backButton.GetComponent<RectTransform>().eulerAngles = rotationBack;
        }
    }
}
